In [1]:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import numpy as np
from IPython.display import display, Math, Latex
import pylab
import itertools
import plot_methods
import optimization_methods
%matplotlib inline
import warnings
warnings.filterwarnings('ignore')
In [2]:
my_function = lambda x, y, z: 16*x**2 + 15*y**2 + 2*z**2 + 0.018*x*y + x-z
In [3]:
result = optimization_methods.conjucate_gradients_method(func=my_function, params=[1,1,1], eps=1e-5)
number of iteration: 2, current point: [ 0.02723464 -0.07409267  0.64556502], function value: 0.3093551596052133
number of iteration: 3, current point: [-3.12305912e-02  8.83946842e-07  2.49943486e-01], function value: -0.14062498807023854
number of iteration: 4, current point: [-3.12518505e-02  1.92185807e-05  2.49951212e-01], function value: -0.14062500045542692
Precision: 2.9117208157957226e-05
In [4]:
plot_methods.plot_implicit(fn=my_function, bbox=(-0.01, 0.01))
In [5]:
func = lambda x, y: x**2 + 4*y**2 + 0.001*x*y - y
In [6]:
plot_methods.plot_function([func], 'Quadratic function')
In [7]:
res = optimization_methods.conjucate_gradients_method(func, [0,1], 1e-5)
number of iteration: 2, current point: [-7.40664784e-05  1.25010116e-01], function value: -0.06250000336386632
Precision: 5.297737671902022e-05
In [ ]: